import 'package:flutter/material.dart';
import 'package:my_app/base/foundation/flutter_extension.dart';
import 'package:my_app/base/net/jd_request.dart';
import 'package:my_app/base/router/router_util.dart';
import 'package:my_app/base/utils/jd_log.dart';
import 'package:my_app/base/widget/basic/base_list_widget.dart';
import 'package:my_app/base/widget/basic/jd_app_bar.dart';
import 'package:my_app/modules/pages/home/models/detail_list_model.dart';
import 'package:my_app/modules/pages/home/widgets/detail_cell.dart';
import 'package:my_app/modules/pages/login/login_tool.dart';
import 'package:my_app/modules/router/router_contract_page.dart';
import 'package:my_app/modules/widgets/jd_button.dart';

class DetailPage extends StatefulWidget {
  final Map<String, dynamic> params;
  const DetailPage({Key? key, required this.params}) : super(key: key);
  get getId => params.getStringNotNull('id');

  @override
  State<DetailPage> createState() => _DetailPageState();
}

class _DetailPageState
    extends CommonListWidgetState<DetailListModel, DetailPage> {
  @override
  void initState() {
    super.initState();
    jdLog('getId---${widget.getId}');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: JDAppBar(
        title: '详情',
        actionWidgets: [
          JDButton(
            minHeight: 30,
            minWidth: 40,
            radius: 10,
            onPressed: () async {
              LoginTool.loginOut();
              await RouterUtil.goRoot(context);
              await RouterContractPage.instance.loginPage
                  .push(context, hideAnimation: true);
            },
            text: '退出登录',
          )
        ],
      ),
      body: super.build(context),
    );
  }

  bool? get mapLocalTestList => true;

  @override
  JDApiRequest get apiUrlRequest =>
      JDApiRequest.post('123').params({'11': '2'});

  @override
  Widget createItemWidget(
      BuildContext context, DetailListModel data, int index) {
    return DetailCell(
      model: data,
    );
  }

  @override
  List<DetailListModel> parsingData(
      bool isDownRequest, Map<String, dynamic> response) {
    List<DetailListModel> list = [];
    list.add(DetailListModel());
    list.add(DetailListModel());
    list.add(DetailListModel());
    list.add(DetailListModel());
    list.add(DetailListModel());

    return list;
  }
}
